package cn.zorbus.laian.application.task;

import cn.hutool.core.io.watch.WatchMonitor;
import cn.hutool.core.io.watch.Watcher;
import cn.zorbus.laian.infrastructure.config.VideoProperties;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;

import static cn.hutool.core.io.watch.WatchMonitor.*;

/**
 * create in 2023/12/4 02:34
 *
 * @author shishaodong
 * @version 0.0.1
 */
@Slf4j
@RequiredArgsConstructor
public class FileWatchMonitorTask implements CommandLineRunner {

    private final VideoProperties properties;

    private final Watcher localfileWatcher;

    @SuppressWarnings("all")
    @Override
    public void run(String... args) {
        WatchMonitor watchMonitor = WatchMonitor.create(properties.getPath(), properties.getMaxDepth(), ENTRY_MODIFY, ENTRY_CREATE, ENTRY_DELETE, OVERFLOW);
        watchMonitor.setWatcher(localfileWatcher);
        watchMonitor.start();
    }
}
